package com.hnhs.controller;

import com.hnhs.mapper.ProductMapper;
import com.hnhs.model.ProductInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/products")
public class ProductController {
    @Resource
    private ProductMapper productMapper;

    @GetMapping
    public List<Map<String, Object>> getAllProducts() {

        List <ProductInfo> se = productMapper.getAllProducts();
        List<Map<String,Object>> mapList= new ArrayList<>();
        for (ProductInfo pro : se) {
            Map<String,Object> map=new HashMap<>();
            map.put("name",pro.getName());
            map.put("value",pro.getCount());
            mapList.add(map);
        }
        return mapList;
    }
}
